﻿using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using LevelEditor.Document;
using LevelEditor.Forms;
using System.Windows.Forms;

namespace LevelEditor.View
{
    public class DoUndoLayerResize : DoUndoNothing
    {
        #region Fields

        int LayerIndex;

        Size DoSize;

        Size UndoSize;

        List<uint> UndoTiles;

        #endregion

        #region Constructors

        public DoUndoLayerResize(MainForm form, int layerIndex, Size size):base(form)
        {
            Layer Layer = form.Level.Layers[LayerIndex];
            LayerIndex = layerIndex;
            DoSize = size;
            UndoSize = Layer.Size;
            UndoTiles = new List<uint>(Layer.Tiles);
        }

        #endregion

        #region Methods

        public override bool Do()
        {
            Cursor.Current = Cursors.WaitCursor;
            Layer Layer = MainForm.Level.Layers[LayerIndex];
            Layer.Resize(DoSize);
            MainForm.LayerViewControl.LayerSizeChanged();
            MainForm.LayerViewControl.Invalidate();
            Cursor.Current = Cursors.Default;
            return base.Do();
        }

        public override void Undo()
        {
            Cursor.Current = Cursors.WaitCursor;
            Layer Layer = MainForm.Level.Layers[LayerIndex];
            Layer.Size = UndoSize;
            Layer.Tiles = new List<uint>(UndoTiles);
            MainForm.LayerViewControl.LayerSizeChanged();
            MainForm.LayerViewControl.Invalidate();
            Cursor.Current = Cursors.Default;
        }

        public override string ToString()
        {
            return "Layer " + LayerIndex.ToString() + " resized";
        }

        #endregion
    }
}
